import React, { useEffect, useState } from 'react'
import Taro from '@tarojs/taro'
import { View,Image } from '@tarojs/components'
import FansSelect from '@/components/fans-select'

import './index.scss'

export default function FansList() {
  const [activeCity,setactiveCity] = useState(null)
  const [hotCity,sethotCity] = useState([])
  const [obtainCitys,setobtainCitys] = useState([])
  useEffect(()=>{
    const loca = Taro.getStorageSync('fans-base')
    if(loca && loca.name){
      setactiveCity(loca || {})
    }
    Taro.$get('/act/home/newfans').then(res=>{
      if(res.code != '1'){
        Taro.$toast(res.message)
        return;
      }
      let qrcodes = res.content.qrcodes
      setobtainCitys(qrcodes || [])
      const hots = res.content.hot
      if(hots.length){
        let arr = []
        hots.map(result=>{
          qrcodes.map(ret=>{
            if(ret.id == result){
              arr.push(ret)
            }
          })
        })
        sethotCity(arr)
      }
    })
  },[])

  
  function handleSelect(e){  ///  选择了粉丝群
    Taro.setStorageSync('fans-base',e)
    Taro.$toast('选择成功','success')
    setTimeout(()=>{
      Taro.navigateBack()
    },1000)
  }

  return (
    <View className="fans-list">
      <FansSelect
          cityClick={handleSelect}
          formatName={'name'}
          activeCity={activeCity}
          hotCity={hotCity}
          obtainCitys={obtainCitys}
          isSearch={false}
      ></FansSelect>
    </View>
  )
}
